//
//  KKShareDialog.m
//  DoMi
//
//  Created by 康凯 on 2016/11/30.
//  Copyright © 2016年 kk. All rights reserved.
//

#import "KKShareDialog.h"
#import <UMSocialCore/UMSocialCore.h>

@implementation KKShareDialog

-(void)awakeFromNib{
    [super awakeFromNib];
    self.container.autoresizingMask =UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    self.container.translatesAutoresizingMaskIntoConstraints = YES;
    
    self.frame = [UIScreen mainScreen].bounds;
    self.container.frame=CGRectMake(8, screenHeight, screenWidth-16, 220);
    self.backgroundColor=[UIColor colorWithRed:0 green:0 blue:0 alpha:0.3];
}

#pragma mark 按钮--取消
- (IBAction)cancelBtn:(id)sender {
    [self dismiss];
}

#pragma makr 弹框--展示
-(void)show{
    [appWindow addSubview:self];
    [UIView animateWithDuration:dialog_animation_time animations:^{
        self.container.transform = CGAffineTransformMakeTranslation(0,-228);
    }];
}
#pragma makr 弹框--消失
-(void)dismiss{
    [UIView animateWithDuration:dialog_animation_time animations:^{
        [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
        self.container.transform = CGAffineTransformIdentity;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}
- (IBAction)weiBoClick:(id)sender {
    [self shareTextToPlatformType:UMSocialPlatformType_Sina];
    [self dismiss];
}
- (IBAction)wXClick:(id)sender {
    [self shareTextToPlatformType:UMSocialPlatformType_WechatSession];
    [self dismiss];
}
- (IBAction)wXCircleClick:(id)sender {
    [self shareTextToPlatformType:UMSocialPlatformType_WechatTimeLine];
    [self dismiss];
}
- (IBAction)qqClick:(id)sender {
    [self shareTextToPlatformType:UMSocialPlatformType_QQ];
    [self dismiss];
}
- (IBAction)qqKongJianClick:(id)sender {
    [self shareTextToPlatformType:UMSocialPlatformType_Qzone];
    [self dismiss];
}

- (void)shareTextToPlatformType:(UMSocialPlatformType)platformType
{
    //创建分享消息对象
    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
    if(platformType==UMSocialPlatformType_Sina){
        //设置文本
        NSString *webUrl=@"http://domi.zhonghouqianyuan.com/MobileJson/Index/ShareView";
        messageObject.text =[NSString stringWithFormat:@"国内顶尖的董秘学习与交流平台 %@",webUrl];
        //创建网页内容对象
        NSString *thumbURL = @"https://dmyjr.oss-cn-beijing.aliyuncs.com/635603670878863308.jpg";
        //创建图片内容对象
        UMShareImageObject *shareObject = [[UMShareImageObject alloc] init];
        shareObject.thumbImage = thumbURL;
        shareObject.shareImage = thumbURL;
        messageObject.shareObject = shareObject;
    }else{
        //创建网页内容对象
        NSString* thumbURL = @"https://dmyjr.oss-cn-beijing.aliyuncs.com/20161226/11979148273455526651.png";
        UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:@"国内顶尖的董秘学习与交流平台" descr:@"专家在线视频课程，渗透挂牌前后实操，业内专家心得分享，汇聚圈内精彩资讯" thumImage:thumbURL];
        //设置网页地址
        shareObject.webpageUrl = @"http://domi.zhonghouqianyuan.com/MobileJson/Index/ShareView";
        //分享消息对象设置分享内容对象
        messageObject.shareObject = shareObject;
    }
    //调用分享接口
    [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
        if (error) {
            NSLog(@"************Share fail with error %@*********",error);
            self.shareCallbackBlock(0);
        }else{
            self.shareCallbackBlock(1);
            NSLog(@"response data is %@",data);
        }
    }];
}



@end
